﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Diagnostics;

namespace Game1_Resist50
{
    class Player : GameObject
    {
        // Singleton.
        static private Player _player = null;
        static public Player Instance()
        {
            if (_player == null)
            {
                _player = new Player();
            }

            Debug.Assert(_player != null);
            return _player;
        }

        static private Bitmap _playerImage = new Bitmap(Bitmap.FromFile(@".\Img\player.png"), 10, 10);
        public override Bitmap ObjectImage()
        {
            return _playerImage;
        }
        public override int ObjectWidth()
        {
            return _playerImage.Width;
        }
        public override int ObjectHeight()
        {
            return _playerImage.Height;
        }
        public override void UpdatePosition()
        {
            if ((_position.X + ObjectWidth() / 2) > GraphicsHelper.BmpWidth)
            {
                _position.X = GraphicsHelper.BmpWidth - ObjectWidth() / 2;
            }
            if ((_position.Y + ObjectHeight() / 2) > GraphicsHelper.BmpHeight)
            {
                _position.Y = GraphicsHelper.BmpHeight - ObjectHeight() / 2;
            }
        }
        public override Rectangle ObjectRectangle()
        {
            return new Rectangle(_position.X, _position.Y, _playerImage.Width, _playerImage.Height);
        }

        // Player API.
        public void SetPosition(int x, int y)
        {
            _position.X = x - ObjectWidth() / 2;
            _position.Y = y - ObjectHeight() / 2;
        }
    }
}
